package com.warmheart.core.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.warmheart.core.ex.ServerException;

/**
 * 
 * @ClassName: JsonUtil
 * @Description: JSON工具类
 * @author ZhangJianyang
 * @date 2025-06-16 09:37:02
 *
 */
public class JsonUtil {

    private static Logger logger = LoggerFactory.getLogger(JsonUtil.class);

    /**
     * 
     * @Title: getJsonStr
     * @Description: 获取JSON字符串
     * @author ZhangJianyang
     * @param obj
     * @return
     * @throws ServerException
     */
    public static String getJsonStr(Object obj) throws ServerException {
        if (obj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        try {
            return mapper.writeValueAsString(obj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getStringMap
     * @Description: 根据JSON字符串获取String类型的MAP
     * @author ZhangJianyang
     * @param jsonStr
     * @param ignoreKeys
     * @return
     * @throws ServerException
     */
    public static Map<String, String> getStringMap(String jsonStr, String... ignoreKeys) throws ServerException {
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        Map<String, Object> currObjMap;
        try {
            currObjMap = mapper.readValue(jsonStr, new TypeReference<Map<String, Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (currObjMap == null) {
            return null;
        }
        Iterator<Entry<String, Object>> it = currObjMap.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, Object> ele = it.next();
            Object value = ele.getValue();
            if (value == null || value.getClass().isArray() || value instanceof List || value instanceof Map) {
                it.remove();
            }
        }
        if (ignoreKeys != null && ignoreKeys.length > 0) {
            for (String currIgnoreKey : ignoreKeys) {
                if (currObjMap.containsKey(currIgnoreKey)) {
                    currObjMap.remove(currIgnoreKey);
                }
            }
        }
        try {
            return mapper.readValue(mapper.writeValueAsString(currObjMap), new TypeReference<Map<String, String>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getMap
     * @Description: 根据JSON字符串获取MAP
     * @author ZhangJianyang
     * @param jsonStr
     * @param ignoreKeys
     * @return
     * @throws ServerException
     */
    public static Map<String, Object> getMap(String jsonStr, String... ignoreKeys) throws ServerException {
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        Map<String, Object> currObjMap;
        try {
            currObjMap = mapper.readValue(jsonStr, new TypeReference<Map<String, Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (currObjMap == null) {
            return null;
        }
        if (ignoreKeys != null && ignoreKeys.length > 0) {
            for (String currIgnoreKey : ignoreKeys) {
                if (currObjMap.containsKey(currIgnoreKey)) {
                    currObjMap.remove(currIgnoreKey);
                }
            }
        }
        try {
            return mapper.readValue(mapper.writeValueAsString(currObjMap), new TypeReference<Map<String, Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }
    
    /**
     * 
     * @Title: getObjMap
     * @Description: 获取对象MAP
     * @author ZhangJianyang
     * @param jsonStr
     * @param cls
     * @param ignoreKeys
     * @return
     * @throws ServerException
     */
    public static <T> Map<String, T> getObjMap(String jsonStr, Class<T> cls, String... ignoreKeys)
            throws ServerException {
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        Map<String, Object> currObjMap;
        try {
            currObjMap = mapper.readValue(jsonStr, new TypeReference<Map<String, Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (currObjMap == null) {
            return null;
        }
        Iterator<Entry<String, Object>> it = currObjMap.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, Object> ele = it.next();
            Object value = ele.getValue();
            if (value != null && !(value instanceof Map)) {
                it.remove();
            }
        }
        if (ignoreKeys != null && ignoreKeys.length > 0) {
            for (String currIgnoreKey : ignoreKeys) {
                if (currObjMap.containsKey(currIgnoreKey)) {
                    currObjMap.remove(currIgnoreKey);
                }
            }
        }
        try {
            return mapper.readValue(mapper.writeValueAsString(currObjMap), mapper.getTypeFactory()
                    .constructParametricType(HashMap.class, String.class, cls));
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getObject
     * @Description: 根据JSON字符串获取对象
     * @author ZhangJianyang
     * @param jsonStr
     * @return
     * @throws ServerException
     */
    public static Object getObject(String jsonStr) throws ServerException {
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        try {
            return mapper.readValue(jsonStr, new TypeReference<Object>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getObject
     * @Description: 根据JSON字符串获取指定类型对象
     * @author ZhangJianyang
     * @param jsonMap
     * @param key
     * @param cls
     * @return
     * @throws ServerException
     */
    public static <T> T getObject(String jsonStr, Class<T> cls) throws ServerException {
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        try {
            return mapper.readValue(jsonStr, cls);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: parseObject
     * @Description: 转换对象类型
     * @author ZhangJianyang
     * @param obj
     * @param cls
     * @return
     * @throws ServerException
     */
    public static <T> T parseObject(Object obj, Class<T> cls) throws ServerException {
        if (obj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(obj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        try {
            return mapper.readValue(jsonStr, cls);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getObjList
     * @Description: 根据JSON字符串获取对象列表
     * @author ZhangJianyang
     * @param jsonStr
     * @return
     * @throws ServerException
     */
    public static List<Object> getObjList(String jsonStr) throws ServerException {
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        try {
            return mapper.readValue(jsonStr, new TypeReference<List<Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getObjList
     * @Description: 根据JSON字符串获取指定类型对象列表
     * @author ZhangJianyang
     * @param jsonStr
     * @param cls
     * @return
     * @throws ServerException
     */
    public static <T> List<T> getObjList(String jsonStr, Class<T> cls) throws ServerException {
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        try {
            return mapper.readValue(jsonStr, mapper.getTypeFactory().constructParametricType(ArrayList.class, cls));
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getStringList
     * @Description: 根据JSON字符串获取字符串列表
     * @author ZhangJianyang
     * @param jsonStr
     * @return
     * @throws ServerException
     */
    public static List<String> getStringList(String jsonStr) throws ServerException {
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        try {
            return mapper.readValue(jsonStr, new TypeReference<List<String>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getString
     * @Description: 根据数据MAP获取指定KEY对应的字符串
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @return
     */
    public static String getString(Map<String, Object> dataMap, String key) {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        return String.valueOf(tempObj);
    }

    /**
     * 
     * @Title: getInteger
     * @Description: 根据数据MAP获取指定KEY对应的整数
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @return
     */
    public static Integer getInteger(Map<String, Object> dataMap, String key) {
        if (dataMap == null) {
            return null;
        }

        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }

        return Integer.parseInt(String.valueOf(tempObj));
    }

    /**
     * 
     * @Title: getLong
     * @Description: 根据数据MAP获取指定KEY对应的长整型
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @return
     */
    public static Long getLong(Map<String, Object> dataMap, String key) {
        if (dataMap == null) {
            return null;
        }

        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }

        return Long.parseLong(String.valueOf(tempObj));
    }

    /**
     * 
     * @Title: getBoolean
     * @Description: 根据数据MAP获取指定KEY对应的布尔型
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @return
     */
    public static Boolean getBoolean(Map<String, Object> dataMap, String key) {
        if (dataMap == null) {
            return null;
        }

        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }

        return Boolean.parseBoolean(String.valueOf(tempObj));
    }

    /**
     * 
     * @Title: getObject
     * @Description: 根据数据MAP获取指定KEY对应的对象
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @return
     */
    public static Object getObject(Map<String, Object> dataMap, String key) {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        return tempObj;
    }

    /**
     * 
     * @Title: getObject
     * @Description: 根据数据MAP获取指定KEY对应的指定类型的对象
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @param cls
     * @return
     * @throws ServerException
     */
    public static <T> T getObject(Map<String, Object> dataMap, String key, Class<T> cls) throws ServerException {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(tempObj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        try {
            return mapper.readValue(jsonStr, cls);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getStringMap
     * @Description: 根据数据MAP获取指定KEY对应的字符串类型MAP
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @param ignoreKeys
     * @return
     * @throws ServerException
     */
    public static Map<String, String> getStringMap(Map<String, Object> dataMap, String key, String... ignoreKeys)
            throws ServerException {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(tempObj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        Map<String, Object> currObjMap;
        try {
            currObjMap = mapper.readValue(jsonStr, new TypeReference<Map<String, Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (currObjMap == null) {
            return null;
        }
        Iterator<Entry<String, Object>> it = currObjMap.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, Object> ele = it.next();
            Object value = ele.getValue();
            if (value == null || value.getClass().isArray() || value instanceof List || value instanceof Map) {
                it.remove();
            }
        }
        if (ignoreKeys != null && ignoreKeys.length > 0) {
            for (String currIgnoreKey : ignoreKeys) {
                if (currObjMap.containsKey(currIgnoreKey)) {
                    currObjMap.remove(currIgnoreKey);
                }
            }
        }
        try {
            return mapper.readValue(mapper.writeValueAsString(currObjMap), new TypeReference<Map<String, String>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getMap
     * @Description: 根据数据MAP获取指定KEY对应的MAP
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @return
     * @throws ServerException
     */
    public static Map<String, Object> getMap(Map<String, Object> dataMap, String key) throws ServerException {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(tempObj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        try {
            return mapper.readValue(jsonStr, new TypeReference<Map<String, Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }
    
    /**
     * 
     * @Title: getObjMap
     * @Description: 获取对象MAP
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @param cls
     * @return
     * @throws ServerException
     */
    public static <T> Map<String, T> getObjMap(Map<String, Object> dataMap, String key, Class<T> cls)
            throws ServerException {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(tempObj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        Map<String, Object> currObjMap;
        try {
            currObjMap = mapper.readValue(jsonStr, new TypeReference<Map<String, Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (currObjMap == null) {
            return null;
        }
        Iterator<Entry<String, Object>> it = currObjMap.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, Object> ele = it.next();
            Object value = ele.getValue();
            if (value != null && !(value instanceof Map)) {
                it.remove();
            }
        }
        try {
            return mapper.readValue(mapper.writeValueAsString(currObjMap), mapper.getTypeFactory()
                    .constructParametricType(HashMap.class, String.class, cls));
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getObjList
     * @Description: 根据数据MAP获取指定KEY对应的对象列表
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @return
     * @throws ServerException
     */
    public static List<Object> getObjList(Map<String, Object> dataMap, String key) throws ServerException {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(tempObj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        try {
            return mapper.readValue(jsonStr, new TypeReference<List<Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getObjList
     * @Description: 根据数据MAP获取指定KEY对应的指定类型的对象列表
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @param cls
     * @return
     * @throws ServerException
     */
    public static <T> List<T> getObjList(Map<String, Object> dataMap, String key, Class<T> cls) throws ServerException {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(tempObj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (StringUtils.isBlank(jsonStr)) {
            return null;
        }
        try {
            return mapper.readValue(jsonStr, mapper.getTypeFactory().constructParametricType(ArrayList.class, cls));
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getStringList
     * @Description: 根据数据MAP获取指定KEY对应的字符串列表
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @return
     * @throws ServerException
     */
    public static List<String> getStringList(Map<String, Object> dataMap, String key) throws ServerException {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(tempObj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        List<Object> currObjList;
        try {
            currObjList = mapper.readValue(jsonStr, new TypeReference<List<Object>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (currObjList == null || currObjList.size() == 0) {
            return null;
        }
        for (Object currObj : currObjList) {
            if (currObj == null || currObj.getClass().isArray() || currObj instanceof List || currObj instanceof Map) {
                currObj = null;
            }
        }
        try {
            return mapper.readValue(mapper.writeValueAsString(currObjList), new TypeReference<List<String>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getArray
     * @Description: 根据数据MAP获取指定KEY对应的MAP列表
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @return
     * @throws ServerException
     */
    public static List<Map<String, Object>> getArray(Map<String, Object> dataMap, String key) throws ServerException {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(tempObj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        try {
            return mapper.readValue(jsonStr, new TypeReference<List<Map<String, Object>>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }

    /**
     * 
     * @Title: getStringArray
     * @Description: 根据数据MAP获取指定KEY对应的字符串MAP列表
     * @author ZhangJianyang
     * @param dataMap
     * @param key
     * @param ignoreKeys
     * @return
     * @throws ServerException
     */
    public static List<Map<String, String>> getStringArray(Map<String, Object> dataMap, String key,
            String... ignoreKeys) throws ServerException {
        if (dataMap == null) {
            return null;
        }
        Object tempObj = dataMap.get(key);
        if (tempObj == null) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(tempObj);
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        List<Map<String, Object>> currObjList;
        try {
            currObjList = mapper.readValue(jsonStr, new TypeReference<List<Map<String, Object>>>() {
            });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
        if (currObjList == null || currObjList.size() == 0) {
            return null;
        }
        for (Map<String, Object> currObjMap : currObjList) {
            Iterator<Entry<String, Object>> it = currObjMap.entrySet().iterator();
            while (it.hasNext()) {
                Entry<String, Object> ele = it.next();
                Object value = ele.getValue();
                if (value == null || value.getClass().isArray() || value instanceof List || value instanceof Map) {
                    it.remove();
                }
            }
            if (ignoreKeys != null && ignoreKeys.length > 0) {
                for (String currIgnoreKey : ignoreKeys) {
                    if (currObjMap.containsKey(currIgnoreKey)) {
                        currObjMap.remove(currIgnoreKey);
                    }
                }
            }
        }
        try {
            return mapper.readValue(mapper.writeValueAsString(currObjList),
                    new TypeReference<List<Map<String, String>>>() {
                    });
        } catch (Exception e) {
            logger.error("数据格式转换异常", e);
            throw new ServerException();
        }
    }
}